const fs = require("fs");
const path = require("path");
const PROCESS_CWD = process.cwd(); // 进程启动位置
const signAliPath = "src/sign/alipay";
const signWXPath = "src/sign/wxpay";
const signIOSPath = "src/sign/ios";
module.exports = {
  domain: "https://www.nadu8.com/",
  cdn: "https://file.nadu8.com/",
  port: 8086,
  xss: null,
  compress: null,
  cache: {
    maxAge: 3600 // 阅览器缓存1个小时
  },
  middlewares: ["logger", "state", "error", "etag", "cros"],
  plugins: [],
  proxy: {
    "/prox": {
      target: "http://www.domain.com",
      changeOrigin: true,
      rewrite: {
        "^/prox": "",
      },
    },
  },
  session: {
    key: "koa:sess" /**  cookie的key。 (默认是 koa:sess) */,
    maxAge: 1000 * 60 * 5 /**  session 过期时间，以毫秒ms为单位计算 。*/,
    autoCommit: true /** 自动提交到响应头。(默认是 true) */,
    overwrite: true /** 是否允许重写 。(默认是 true) */,
    httpOnly: true /** 是否设置HttpOnly，如果在Cookie中设置了"HttpOnly"属性，那么通过程序(JS脚本、Applet等)将无法读取到Cookie信息，这样能有效的防止XSS攻击。  (默认 true) */,
    signed: true /** 是否签名。(默认是 true) */,
    rolling: true /** 是否每次响应时刷新Session的有效期。(默认是 false) */,
    renew: false /** 是否在Session快过期时刷新Session的有效期。(默认是 false) */,
  },
  db: {
    redis: {
      clients: {
        1: {
          db: 1,
          host: "127.0.0.1",
          password: "***",
          keyPrefix: "EMAIL_CODE_",
        },
      },
      default: {
        port: 6379,
        db: 0,
        keyPrefix: "",
      },
      cacheTime: 1800, // 秒为单位
      isCache: true,
    },
    mysql: {
      default: {
        user: "root",
        port: 3306,
        dialect: "mysql",
        logging: true, // 是否开启日志
        pool: {
          max: 5, // 连接池最大保持连接数（process）
          min: 0,
          acquire: 30000,
          idle: 10000,
        },
        dialectOptions: {
          dateStrings: "TIMESTAMP",
          typeCast: true,
          multipleStatements: true,
        },
        timezone: "+08:00",
      },
    },
  },
  // acsses_token和密码加密
  mixin: {
    aesKey: "colpuManagerAuth", // aesKey密钥必须16个字符
    salt: "oYHz2kn8y+ipyoUTtwdi3g==",
    expire: [1, "M"], // 年:y,季度:Q;几个月:M;周:w;天:d;小时:h;分钟:m;秒:s;毫秒:ms
  },
  appConfig: {
    keys: "colpu-session-secret-2020",
    proxy: true,
  },
  /**
   * AES解密相关
   *
   * aes_key: md5(32)=> foindia2023colpu
   * const AES_KEY = '30209b53f62320e54340ce19fd22b0d9';
   * aes_iv: md5(16)=> uploc3202aidniof
   * 将此数据混入数据中，分别插入到数据的从第一个字符开始分别插入，如果不够则不再插入
   * const AES_IV = '061f5be731462295';
   * const AES_DATA = 'foindia';
   */
  aes: {
    key: "30209b53f62320e54340ce19fd22b0d9",
    iv: "061f5be731462295",
    data: "foindia",
  },
  alipay: {
    notifyUrl: "https://api.nadu8.com/alipay",
    appId: "2021003189648028",
    aseKey: "***",
    publicKey: fs.readFileSync(
      path.join(PROCESS_CWD, signAliPath, "publicKey.txt"),
      "utf-8"
    ),
    privateKey: fs.readFileSync(
      path.join(PROCESS_CWD, signAliPath, "privateKey.txt"),
      "utf-8"
    ),
    certPublicKeyRSA2: path.join(
      PROCESS_CWD,
      signAliPath,
      "alipayCertPublicKey_RSA2.crt"
    ),
    certPublicKey: path.join(
      PROCESS_CWD,
      signAliPath,
      "appCertPublicKey_2021003189648028.crt"
    ),
    rootCert: path.join(PROCESS_CWD, signAliPath, "alipayRootCert.crt"),
  },
  wxpay: {
    appId: "***",
    mchid: "***5",
    serialNo: "***",
    publicKey: fs.readFileSync(
      path.join(PROCESS_CWD, signWXPath, "apiclient_cert.pem"),
      "utf-8"
    ),
    privateKey: fs.readFileSync(
      path.join(PROCESS_CWD, signWXPath, "apiclient_key.pem"),
      "utf-8"
    ),
    apiv3: "***", // 这里使用AES_KEY再次MD5获得
    notifyUrl: "https://api.nadu8.com/wechatpay",
  },
  iospay: {
    sharedKey: "***",
    authKey: fs.readFileSync(
      path.join(PROCESS_CWD, signIOSPath, "AuthKey_QQ455P2H3R.p8"),
      "utf-8"
    ),
    subscriptionKey: fs.readFileSync(
      path.join(PROCESS_CWD, signIOSPath, "SubscriptionKey_MJQF4S82PG.p8"),
      "utf-8"
    ),
  },
  iosAuth: {
    name: "foindia",
    keyId: "YTH9PK9MYC",
    authKey: fs.readFileSync(
      path.join(PROCESS_CWD, signIOSPath, "AuthKey_YTH9PK9MYC.p8"),
      "utf-8"
    ),
    teamId: "***",
    bundleId: "***",
    serviceId: "***",
    redirectUri: "https://api.nadu8.com/apple_auth_callback",
  },
  umeng: {
    api: "https://msgapi.umeng.com",
    appKey: "***",
    masterSecret: "***",
  },
  fileCache: {
    // 是否文件缓存
    suffix: "txt",
    isCache: true,
    cacheQuery: true, // 默认缓存path,不缓存query,post请求不做缓存
    cacheTime: 1800, // 秒为单位
  },
  // email 发送
  smtp: {
    host: "smtp.qq.com",
    port: 465,
    pool: true,
    secure: true,
    logger: true,
    transactionLog: true,
    allowInternalNetworkInterfaces: false,
    auth: {
      user: "***",
      pass: "***",
    },
    cacheTime: 60 * 0.5, // 秒为单位
  },
  alioss: {
    default: {
      accessKeyId: "***",
      accessKeySecret: "***",
      endpoint: "http://oss-cn-hangzhou-internal.aliyuncs.com",
      accessDomain: "http://colpu-file.oss-cn-hangzhou-internal.aliyuncs.com",
      arn: "acs:ram::1184036967255532:role/stsrole", // 自定义的权限策略名称
      bucket: "colpu-file",
      customFolder: "",
      domain: "//file.nadu8.com",
      policy: {
        Version: "1",
        Statement: [
          {
            Action: ["oss:PutObject", "oss:GetObject"],
            Effect: "Allow",
            // 这里$resource可以控制具体到哪个目录或者文件比如：
            // 1、具体目录colpu-file/*
            // 2、具体文件colpu-file/test/1.jpg
            Resource: ["acs:oss:*:*:$resource"],
          },
        ],
      },
    },
    foindia: {
      accessKeyId: "***",
      accessKeySecret: "***",
      endpoint: "oss-cn-beijing.aliyuncs.com",
      accessDomain: "http://foindia.oss-cn-beijing.internal.aliyuncs.com",
      arn: "acs:ram::1184036967255532:role/stsrole", // 自定义的权限策略名称
      bucket: "foindia",
      customFolder: "",
      domain: "https://file.nadu8.com",
      policy: {
        Version: "1",
        Statement: [
          {
            Action: ["oss:PutObject", "oss:GetObject"],
            Effect: "Allow",
            // 这里$resource可以控制具体到哪个目录或者文件比如：
            // 1、具体目录colpu-file/*
            // 2、具体文件colpu-file/test/1.jpg
            Resource: ["acs:oss:*:*:$resource"],
          },
        ],
      },
    },
  },
};
